home *** CD-ROM | disk | FTP | other *** search
/ Chip: Special XP & Vista / Chip Spesial XP & Vista.iso / 3_Gadgets / UEFA_Informer_Gadget / UEFAinfo.gadget / scripts / menu.js < prev    next >
Text (UTF-16)  |  2008-03-28  |  17KB  |  277 lines

  1. var prevPoint;
  2. var checkedValue;
  3. //  checkedValue = [countryId;countryName;logo]
  4. var countrySelId;
  5. var numSelOption;
  6. var paramFlyout;
  7.  
  8. function init_Menu()
  9. {
  10.     if (System.Gadget.Settings.read("checkedValue"))
  11.     {
  12.         checkedValue = System.Gadget.Settings.read("checkedValue").split(",");
  13.         if (System.Gadget.Settings.read("countrySelId"))
  14.         {
  15.             countrySelId = System.Gadget.Settings.read("countrySelId");
  16.             numSelOption = System.Gadget.Settings.read("numSelOption");
  17.         }
  18.         else
  19.         {
  20.             countrySelId = checkedValue[0].split(";")[0];//first point mainmenu
  21.             numSelOption = 0;// first point submenu
  22.         }
  23.     }
  24.     else
  25.     {  
  26.         // Default settings menu
  27.         set_DefaultMenu();
  28.         countrySelId = checkedValue[0].split(";")[0];//first point mainmenu
  29.         numSelOption = 0;// first point submenu
  30.         System.Gadget.Settings.write("checkedValue", checkedValue);
  31.     }
  32.     get_League();
  33. }
  34.  
  35. function set_DefaultMenu()
  36. {
  37.     checkedValue    = [];
  38.     checkedValue[0] = "-1;Champions League;UCL.gif";
  39.     checkedValue[1] = "-2;UEFA Cup;uefacup.gif";
  40.     checkedValue[2] = "-3;Euro2008;euro2008.gif";
  41.     checkedValue[3] = "2;England;England.gif";
  42.     checkedValue[4] = "8;France;France.gif";
  43.     checkedValue[5] = "6;Germany;Germany.gif";
  44.     checkedValue[6] = "4;Italy;Italy.gif";
  45.     checkedValue[7] = "3;Spain;Spain.gif";
  46.     checkedValue[8] = "18;Ukraine;Ukraine.gif";
  47. }
  48.  
  49. function get_League()
  50. {
  51.      var content = document.getElementById("content");
  52.      content.innerHTML = "<p class='centered'><img src='images/loaderMain.gif'></p>";
  53.     show_Back();        
  54.     
  55.     //UEFA competitions
  56.     if (countrySelId < 0)
  57.     {
  58.         var url = "http://soccerdb.890m.com/xml/uefalist12.xml?a=1" + refreshRandom;
  59.     }
  60.     //National leagues
  61.     if (countrySelId > 0)
  62.     {
  63.           var url = "http://mbovin.com/soccerdb/export/grouplist.php?countryId=" + countrySelId + refreshRandom;
  64.     }
  65.     if (countrySelId == 0) return;
  66.     var httpreq = getHTTPObject();
  67.     httpreq.open("GET", url, true);
  68.     httpreq.onreadystatechange = function ()
  69.     {
  70.         if (httpreq.readyState == 4)
  71.         {
  72.           if (httpreq.status == 200)
  73.           {
  74.                var xml = httpreq.responseXML;
  75.             create_Menu(xml);
  76.           } else
  77.             {
  78.             content.innerHTML = "<p class='centered'>Error: Status " + httpreq.status + "  (" + httpreq.statusText + ")</p>";
  79.             }            
  80.         }
  81.     }
  82.     httpreq.send ();    
  83. }
  84.  
  85. function create_Menu(xml)
  86. {
  87.     var lbFeeds = document.getElementById("lbFeeds");
  88.     lbFeeds.innerHTML = "";//Cleaning menu
  89.  
  90.     //Create main section of menu
  91.     create_Option(0, "--------- Select --------", lbFeeds);    
  92.     for (var i = 0; i < checkedValue.length; i++)
  93.     {
  94.         var countryValue = checkedValue[i];
  95.         var countryId      = countryValue.split(";")[0];
  96.         var countryName  = countryValue.split(";")[1];
  97.         var valueStr     = "country;" + countryValue;
  98.         
  99.         if (countrySelId == countryId)
  100.         {
  101.             var countrySelValue = countryValue;
  102.             var countrySelName    = countryName;
  103.         } else
  104.           {
  105.               create_Option(valueStr, countryName, lbFeeds);
  106.           }        
  107.     }
  108.     create_Option(0, "----------------------------", lbFeeds);
  109.  
  110.     //Create subMenu section
  111.     if (countrySelId < 0)//UEFA leagues
  112.     {
  113.         var leagueNode = xml.documentElement.getElementsByTagName("league");
  114.         for (var i = 0; i < leagueNode.length; i++)
  115.         {
  116.             var countryId = getAttributeValue(leagueNode[i], "countryid");
  117.             if (countrySelId == countryId) 
  118.             {
  119.                 var stageNode = leagueNode[i].childNodes;
  120.                 //Add headline
  121.                 create_Option(0, countrySelName, lbFeeds, "#224871");
  122.             }
  123.         }
  124.     }
  125.     if (countrySelId > 0)//National leagues
  126.     {
  127.         var stageNode = xml.documentElement.getElementsByTagName("group");
  128.         //Add headline
  129.         var optgroup = document.createElement("optgroup");
  130.         optgroup.label = countrySelName;
  131.         lbFeeds.appendChild(optgroup);
  132.  
  133.     }
  134.     var optionSubMenu = 0;
  135.     for (var i = 0; i < stageNode.length; i++)
  136.     {
  137.         //Stage level
  138.         var leagueId   = getAttributeValue(stageNode[i], "leagueid");
  139.         var stageId    = getAttributeValue(stageNode[i], "stageid");
  140.         var stageName  = getChildNodeValue(stageNode[i], "name");
  141.         var stageValue = countrySelValue + ";" + leagueId + ";" + stageId + ";" + stageName;
  142.         var multigroup = getAttributeValue(stageNode[i], "multigroup");
  143.  
  144.         switch (multigroup)
  145.         {
  146.             case "-1": //play-off format
  147.                 if (countrySelId > 0) break;
  148.                 var valueStr     = "play-off;" + stageValue;
  149.                 create_Option(valueStr, stageName, lbFeeds);
  150.                 optionSubMenu += 1;
  151.                 break;
  152.             case "0"://group format
  153.                 //Group level
  154.                 var valueStr     = "group;" + stageValue;
  155.                 create_Option(valueStr, stageName, optgroup);
  156.                 optionSubMenu += 1;
  157.                 break;
  158.             case "1": //multigroup format
  159.                 if (countrySelId > 0) break;
  160.                 //Add headline
  161.                 var optgroup     = document.createElement("optgroup");
  162.                 optgroup.label     = stageName;
  163.                 lbFeeds.appendChild(optgroup);
  164.                 //Group level
  165.                 var groupNode = stageNode[i].childNodes;
  166.                     for (var j = 0; j < groupNode.length; j++)
  167.                     {
  168.                         if (groupNode[j].nodeName == "group")
  169.                         {
  170.                             var groupId     = getAttributeValue(groupNode[j], "id");
  171.                             var groupName     = getChildNodeValue(groupNode[j], "name");
  172.                             var groupValue     = stageValue + ";" + groupId + ";" + groupName;
  173.                             var valueStr    = "multigroup;" + groupValue;
  174.                             create_Option(valueStr, groupName, optgroup);
  175.                             optionSubMenu += 1;
  176.                         }
  177.                     }
  178.                 break;
  179.         }
  180.     }
  181.     // Set selected option
  182.     if (numSelOption == 0)
  183.     {
  184.         numSelOption = lbFeeds.options.length - optionSubMenu;// first point submenu
  185.     }
  186.     lbFeeds.selectedIndex = numSelOption;    
  187.     valueStr = lbFeeds.options[numSelOption].value;
  188.     change_Menu(valueStr);
  189. }
  190.  
  191. function change_Menu(valueStr)
  192. {
  193.     var lbFeeds    = document.getElementById("lbFeeds");
  194.     var leagueName = document.getElementById("leagueName");
  195.     var content = document.getElementById("content");
  196.     
  197.     if (valueStr == 0)//Nothing selected
  198.     {
  199.         lbFeeds.selectedIndex = prevPoint;
  200.         return;
  201.     }    
  202.     var valueArr = valueStr.split(";");
  203. //  var valueStr = [country || play-off || group || multigroup;
  204. //                 countryId;countryName;logo;
  205. //                 leagueId;
  206. //                 stageId;stageName;
  207. //                 groupId;groupName]
  208.  
  209.     switch (valueArr[0])
  210.     {
  211.         case "country"://New league selected
  212.             countrySelId = valueArr[1];
  213.             numSelOption = 0;
  214.             System.Gadget.Settings.write("countrySelId", countrySelId);
  215.             get_League();
  216.             return;
  217.         case "play-off"://Play-off match selected
  218.             var countryName    = valueArr[2];
  219.             var logo        = valueArr[3];
  220.             var leagueId    = valueArr[4];
  221.             var stageId        = valueArr[5];
  222.             var stageName    = valueArr[6];
  223.             var paramStage        = "stageId=" + stageId;    
  224.             prevPoint = lbFeeds.selectedIndex;
  225.             System.Gadget.Settings.write("numSelOption", prevPoint);
  226.             content.innerHTML = "<br>Click link below to view <b>" + stageName + "</b> match results";
  227.             show_Back();
  228.             document.getElementById("flyOn").style.display = "";
  229.             resize_Win();
  230.             break;
  231.         case "group"://Group selected
  232.             var countryName    = valueArr[2];
  233.             var logo         = valueArr[3];
  234.             var leagueId    = valueArr[4];
  235.             var stageId        = valueArr[5];
  236.             var stageName    = valueArr[6];
  237.             var paramStage        = "stageId=" + stageId;    
  238.                leagueName.innerHTML = countryName + "<br>" + stageName;//Table header
  239.             prevPoint = lbFeeds.selectedIndex;
  240.             System.Gadget.Settings.write("numSelOption", prevPoint);
  241.             get_TableXML(paramStage);
  242.             break;
  243.         case "multigroup"://Multigroup selected
  244.             var countryName    = valueArr[2];
  245.             var logo         = valueArr[3];
  246.             var leagueId    = valueArr[4];
  247.             var stageId        = valueArr[5];
  248.             var stageName    = valueArr[6];
  249.             var groupId        = valueArr[7];
  250.             var groupName    = valueArr[8];
  251.             var paramStage        = "stageId=" + stageId + "&" + "groupId=" + groupId;
  252.             leagueName.innerHTML = countryName + "<br>" + stageName + "<br>" + groupName;//Table header
  253.             prevPoint = lbFeeds.selectedIndex;
  254.             System.Gadget.Settings.write("numSelOption", prevPoint);
  255.             get_TableXML(paramStage);
  256.             // Replacement for flyout parametrs
  257.             countryName = stageName;
  258.             stageName   = groupName;
  259.             break;
  260.     }
  261.     // Parameters for opening flyout window
  262.     paramFlyout  = paramStage + ";";
  263.     paramFlyout += logo + ";";
  264.     paramFlyout += countryName + ";";
  265.     paramFlyout += stageName + ";";
  266.     paramFlyout += leagueId;
  267. }
  268.     
  269. function create_Option(value, text, parentNode, colorFont)
  270. {
  271.     var option = document.createElement("option");
  272.     option.value = value;
  273.     option.innerText = text;
  274.     if (colorFont != "") option.style.color = colorFont;
  275.     parentNode.appendChild(option);
  276. }
  277.